#
# Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
#
# GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
# Author: Shawn.Tan
# Date: 2025.10.28
#
# History: Initial Version 2025.10.28
#
#
from gpgpu.EnvGPGPU import EnvGPGPU
from gpgpu.GenThreadGPGPU import GenThreadGPGPU
from base.Sequence import Sequence


# This test verifies that generating compressed load and store
# instructions without preamble with uninitialized registers doesn't fail.
class MainSequence(Sequence):
    def generate(self, **kargs):

        instructions = (
            "C.FLD##CALM",
            "C.FSD##CALM",
            "C.LD##CALM",
            "C.LW##CALM",
            "C.SD##CALM",
            "C.SW##CALM",
        )

        if self.getGlobalState("AppRegisterWidth") == 32:
            instructions = (
                "C.FLD##CALM",
                "C.FSD##CALM",
                "C.LW##CALM",
                "C.SW##CALM",
            )

        for _ in range(50):
            instr_id = self.genInstruction(self.choice(instructions), {"NoPreamble": 1})

            if instr_id:
                instr_record = self.queryInstructionRecord(instr_id)

                if (instr_record["Addressing"]["Base"][0] < 8) or (
                    instr_record["Addressing"]["Base"][0] > 15
                ):
                    self.error(
                        "Expected a base register index between 8 and 15; "
                        "Actual=%d" % instr_record["Addressing"]["Base"][0]
                    )


MainSequenceClass = MainSequence
GenThreadClass = GenThreadGPGPU
EnvClass = EnvGPGPU
